{-
	Graph Module
	
	r36
	
	29 March 2010
	
	Daniel De Guzman
	
	This module is part of the FPT Algorithm Implementation Project for the Massey University
	paper: 159.402 Programming Languages. This module contains functions pertaining to graph
	creation and retrieval.
-}
module Graph where

import Datatypes
import Words
import Char

-- |=========================================================================================|
-- | 							Graph Creation and Initialization							 |
-- |=========================================================================================|
-- Make tuples of graph by taking vertex info
initializeGraph :: GraphInfo -> Graph
initializeGraph [] = []
initializeGraph (x:xs)
	= (putVertexLabel x, drop 2 $ putNeighbours x):initializeGraph xs
	
-- Get the vertex label from a line
putVertexLabel :: String -> Vertex
putVertexLabel [] = ""
putVertexLabel v = reverse $ drop 1 $ reverse $ getWord v

-- get neighbours
putNeighbours :: String -> Neighbours
putNeighbours [] = []
putNeighbours (x:xs)
	| elem x [' ']	= putNeighbours xs
	| otherwise 	= getWord (x:[]) : putNeighbours xs

-- |-----------------------------------------------------------------------------------------|

-- |=========================================================================================|
-- | 							   Graph Information Retrieval								 |
-- |=========================================================================================|

-- Retrieve the vertex
getVertexLabel :: GraphEntry -> Vertex
getVertexLabel (x, list) = x

-- Retrieve a vertex's neighbours
getNeighbours :: GraphEntry -> Neighbours
getNeighbours (x, list) = list
	
-- Unzip a graph to easily get the array of vertices and the array of neighbours
unzipGraph :: Graph -> ([Vertex], [Neighbours])
unzipGraph graph = unzip graph

-- Retrieve the vertices
getAllVertices :: ([Vertex], [Neighbours]) -> [Vertex]
getAllVertices (v,n) = v

-- Retrieve the neighbours
getAllNeighbours :: ([Vertex], [Neighbours]) -> [Neighbours]
getAllNeighbours (v,n) = n

-- |-----------------------------------------------------------------------------------------|
-- |=========================================================================================|